home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
multiprocessing
/
process.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2014-12-31
|
9KB
|
285 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
__all__ = [
'Process',
'current_process',
'active_children']
import os
import sys
import signal
import itertools
try:
ORIGINAL_DIR = os.path.abspath(os.getcwd())
except OSError:
ORIGINAL_DIR = None
def current_process():
'''
Return process object representing the current process
'''
return _current_process
def active_children():
'''
Return list of process objects corresponding to live child processes
'''
_cleanup()
return list(_current_process._children)
def _cleanup():
for p in list(_current_process._children):
if p._popen.poll() is not None:
_current_process._children.discard(p)
continue
class Process(object):
'''
Process objects represent activity that is run in a separate process
The class is analagous to `threading.Thread`
'''
_Popen = None
def __init__(self, group = None, target = None, name = None, args = (), kwargs = { }):
if not group is None:
raise AssertionError('group argument must be None for now')
count = None._counter.next()
self._identity = _current_process._identity + (count,)
self._authkey = _current_process._authkey
self._daemonic = _current_process._daemonic
self._tempdir = _current_process._tempdir
self._parent_pid = os.getpid()
self._popen = None
self._target = target
self._args = tuple(args)
self._kwargs = dict(kwargs)
if not name:
pass
self._name = type(self).__name__ + '-' + ':'.join((lambda .0: pass)(self._identity))
def run(self):
'''
Method to be run in sub-process; can be overridden in sub-class
'''
if self._target:
self._target(*self._args, **self._kwargs)
def start(self):
'''
Start child process
'''
if not self._popen is None:
raise AssertionError('cannot start a process twice')
if not None._parent_pid == os.getpid():
raise AssertionError('can only start a process object created by current process')
if not not (None._daemonic):
raise AssertionError('daemonic processes are not allowed to have children')
None()
if self._Popen is not None:
Popen = self._Popen
else:
Popen = Popen
import forking
self._popen = Popen(self)
_current_process._children.add(self)
def terminate(self):
'''
Terminate process; sends SIGTERM signal or uses TerminateProcess()
'''
self._popen.terminate()
def join(self, timeout = None):
'''
Wait until child process terminates
'''
if not self._parent_pid == os.getpid():
raise AssertionError('can only join a child process')
if not None._popen is not None:
raise AssertionError('can only join a started process')
res = None._popen.wait(timeout)
if res is not None:
_current_process._children.discard(self)
def is_alive(self):
'''
Return whether process is alive
'''
if self is _current_process:
return True
if not None._parent_pid == os.getpid():
raise AssertionError('can only test a child process')
if None._popen is None:
return False
None._popen.poll()
return self._popen.returncode is None
def name(self):
return self._name
name = property(name)
def name(self, name):
if not isinstance(name, basestring):
raise AssertionError('name must be a string')
self._name = None
name = name.setter(name)
def daemon(self):
'''
Return whether process is a daemon
'''
return self._daemonic
daemon = property(daemon)
def daemon(self, daemonic):
'''
Set whether process is a daemon
'''
if not self._popen is None:
raise AssertionError('process has already started')
self._daemonic = None
daemon = daemon.setter(daemon)
def authkey(self):
return self._authkey
authkey = property(authkey)
def authkey(self, authkey):
'''
Set authorization key of process
'''
self._authkey = AuthenticationString(authkey)
authkey = authkey.setter(authkey)
def exitcode(self):
'''
Return exit code of process or `None` if it has yet to stop
'''
if self._popen is None:
return self._popen
return None._popen.poll()
exitcode = property(exitcode)
def ident(self):
'''
Return identifier (PID) of process or `None` if it has yet to start
'''
return None if self is _current_process else self._popen.pid
ident = property(ident)
pid = ident
def __repr__(self):
if self is _current_process:
status = 'started'
elif self._parent_pid != os.getpid():
status = 'unknown'
elif self._popen is None:
status = 'initial'
elif self._popen.poll() is not None:
status = self.exitcode
else:
status = 'started'
return None % ('<%s(%s, %s%s)>', type(self).__name__, self._name, status if type(status) is int else '')
def _bootstrap(self):
global _current_process
util = util
import
try:
self._children = set()
self._counter = itertools.count(1)
try:
sys.stdin.close()
sys.stdin = open(os.devnull)
except (OSError, ValueError):
pass
_current_process = self
util._finalizer_registry.clear()
util._run_after_forkers()
util.info('child process calling self.run()')
try:
self.run()
exitcode = 0
finally:
util._exit_function()
except SystemExit:
e = None
if not e.args:
exitcode = 1
elif isinstance(e.args[0], int):
exitcode = e.args[0]
else:
sys.stderr.write(str(e.args[0]) + '\n')
sys.stderr.flush()
exitcode = 0 if isinstance(e.args[0], str) else 1
except:
exitcode = 1
import traceback as traceback
sys.stderr.write('Process %s:\n' % self.name)
sys.stderr.flush()
traceback.print_exc()
util.info('process exiting with exitcode %d' % exitcode)
return exitcode
class AuthenticationString(bytes):
def __reduce__(self):
Popen = Popen
import forking
if not Popen.thread_is_spawning():
raise TypeError('Pickling an AuthenticationString object is disallowed for security reasons')
return (AuthenticationString, (bytes(self),))
class _MainProcess(Process):
def __init__(self):
self._identity = ()
self._daemonic = False
self._name = 'MainProcess'
self._parent_pid = None
self._popen = None
self._counter = itertools.count(1)
self._children = set()
self._authkey = AuthenticationString(os.urandom(32))
self._tempdir = None
_current_process = _MainProcess()
del _MainProcess
_exitcode_to_name = { }
for name, signum in signal.__dict__.items():
if name[:3] == 'SIG' and '_' not in name:
_exitcode_to_name[-signum] = name
continue